package peitong.peitong_oa.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import peitong.peitong_oa.domain.pojo.Staff;

import java.util.List;

@Mapper
@Component("StaffDao")
public interface StaffDao {
    @Select("<script>select * from t_staff where grade=0<if test=\"value != null and value.length > 0\">"+
            " and (  code =#{value} or name like CONCAT('%',#{value},'%'))</if></script>")
    List<Staff> findbycodeandname(String value);
    @Insert("<script>Insert into t_staff values <foreach" +
            " collection='list' item='staff' separator=','>(null,#{staff.code},#{staff.name},#{staff.sex},#{staff.department},#{staff.position},#{staff.idcard},#{staff.phonenumber},#{staff.address},#{staff.current_address},#{staff.hiredate},#{staff.family_phone},#{staff.remarks},#{staff.grade})</foreach></script>")
    void batchaddstaff(List<Staff> list);
    @Select("<script>select * from t_staff where grade=1<if test=\"value != null and value.length > 0\">"+
            "and  (code =#{value} or name like CONCAT('%',#{value},'%') or department=#{value})</if> <if test=\"value2 != null and value2.length > 0\">and department=#{value2}</if> </script>")
    List<Staff> findstaffbycodeandname( @Param("value") String value,@Param("value2")String value2);
    @SelectKey(statement = "select last_insert_id()",keyProperty = "id",before = false,resultType = Integer.class)
    @Insert("INSERT INTO t_staff VALUES (null,#{staff.code},#{staff.name},#{staff.sex},#{staff.department},#{staff.position},#{staff.idcard},#{staff.phonenumber},#{staff.address},#{staff.current_address},#{staff.hiredate},#{staff.family_phone},#{staff.remarks},#{staff.grade})")
    void addstaff(@Param("staff") Staff staff);
    @Delete("delete from t_staff where id = #{id}")
    void deletebyid(Integer id);
    @Select("select * from t_staff where id =#{id}")
    Staff findStaffDetail(Integer id);
}
